﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Data;

namespace agent02.Model
{
    public class TransportSearchModel
    {
        public SelectList countryList { get; set; }
        public SelectList seatNumList { get; set; }
        public SelectList serviceNameList { get; set; }
        public string country { get; set; }
        public string seatNum { get; set; }
        public string serviceName { get; set; }

        public TransportSearchModel()
        {
            countryList = new SelectList( new[] { "Korea", "Singapore", "Cambodia", "ThaiLand" } );
            seatNumList = new SelectList(new[] { "16 chỗ", "20 chỗ", "4 chỗ", "50 chỗ", "6 chỗ" });
            serviceNameList = new SelectList(new[] { "Xe cưới", "Xe đưa đón khách sân bay", "Xe du lịch" });
        }
    }

    public class XE
    {
        public Int32 MaXe { get; set; }
        public string TenLoai { get; set; }
        public string HieuXe { get; set; }
        public string TenDV { get; set; }
        public double GiaCa { get; set; }
        public Int32 TongSoXe { get; set; }
    }

    public class BANG_GIA_NGAY
    {
        public string TenLoai { get; set; }
        public string HieuXe { get; set; }
        public double GiaTien { get; set; }
        public double GiaNgoaiGio { get; set; }
        public double GiaTrangTri { get; set; }
        public string TenQG { get; set; }
        public double ChiPhiTaiXe { get; set; }
        public double PhiLuuDem { get; set; }
    }

    public class BANG_GIA_MIEN
    {
        public string LoTrinh { get; set; }
        public double SoKM { get; set; }
        public string TenLoai { get; set; }
        public string HieuXe { get; set; }
        public double GiaTien { get; set; }
        public Int32 SoNgay { get; set; }
        public double ChiPhiVuotKM { get; set; }
    }

    public class TransportConverterModel
    {
        public IEnumerable<XE> ConvertToXE(DataTable dt)
        {
            foreach (DataRow dr in dt.Rows)
            {
                yield return new XE
                {
                    MaXe = Convert.ToInt32(dr[0]),
                    TenLoai = Convert.ToString(dr[1]),
                    HieuXe = Convert.ToString(dr[2]),
                    TenDV = Convert.ToString(dr[3]),
                    GiaCa = Convert.ToDouble(dr[4]),
                    TongSoXe = Convert.ToInt32(dr[5])
                };
            }
        }

        public IEnumerable<BANG_GIA_NGAY> ConvertToBANG_GIA_NGAY(DataTable dt)
        {
            foreach (DataRow dr in dt.Rows)
            {
                double gt = 0; // gia tien
                double gng = 0; // gia ngoai gio
                double gtt = 0; // gia trang tri
                double cptx = 0; // chi phi tai xe
                double pld = 0; // phi luu dem
                
                if (dr[2] != DBNull.Value) { gt = Convert.ToDouble(dr[2]); }
                if (dr[3] != DBNull.Value) { gng = Convert.ToDouble(dr[3]); }
                if (dr[4] != DBNull.Value) { gtt = Convert.ToDouble(dr[4]); }
                if (dr[6] != DBNull.Value) { cptx = Convert.ToDouble(dr[6]); }
                if (dr[7] != DBNull.Value) { pld = Convert.ToDouble(dr[7]); }

                yield return new BANG_GIA_NGAY
                {
                    TenLoai = Convert.ToString(dr[0]),
                    HieuXe = Convert.ToString(dr[1]),
                    GiaTien = gt,
                    GiaNgoaiGio = gng,
                    GiaTrangTri = gtt,
                    TenQG = Convert.ToString(dr[5]),
                    ChiPhiTaiXe = cptx,
                    PhiLuuDem = pld
                };
            }
        }

        public IEnumerable<BANG_GIA_MIEN> ConvertToBANG_GIA_MIEN(DataTable dt)
        {
            foreach (DataRow dr in dt.Rows)
            {
                double sk = 0; // so km
                double gt = 0; // gia tien
                Int32 sn = 0; // so ngay
                double cpvk = 0; // chi phi vuot km

                if (dr[1] != DBNull.Value) { sk = Convert.ToDouble(dr[1]); }
                if (dr[4] != DBNull.Value) { gt = Convert.ToDouble(dr[4]); }
                if (dr[5] != DBNull.Value) { sn = Convert.ToInt32(dr[5]); }
                if (dr[6] != DBNull.Value) { cpvk = Convert.ToDouble(dr[6]); }

                yield return new BANG_GIA_MIEN
                {
                    LoTrinh = Convert.ToString(dr[0]),
                    SoKM = sk,
                    TenLoai = Convert.ToString(dr[2]),
                    HieuXe = Convert.ToString(dr[3]),
                    GiaTien = gt,
                    SoNgay = sn,
                    ChiPhiVuotKM = cpvk
                };
            }
        }
    }
}